﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Morse;

namespace WP
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        private SoundTask Task;
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = new MorseCode { Text = "hello world" };
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var mc = this.DataContext as MorseCode;
            Task = Sound.Play(mc.Code);
            ToggleBtn();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            var mc = this.DataContext as MorseCode;
            NavigationService.Navigate(new Uri("/Light.xaml?code="+mc.Code, UriKind.Relative));
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            if (Task != null)
                Task.Stop();
            ToggleBtn();
        }
        private void ToggleBtn()
        {
            btnStart.Visibility = btnStart.Visibility == System.Windows.Visibility.Visible ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
            btnStop.Visibility = btnStop.Visibility == System.Windows.Visibility.Visible ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
        }
    }
}